//package jdbc;
//
//import JDBC3.Brand;
//import com.alibaba.druid.pool.DruidDataSourceFactory;
//
//import javax.sql.DataSource;
//import java.io.File;
//import java.io.FileInputStream;
//import java.sql.Connection;
//import java.sql.PreparedStatement;
//import java.sql.ResultSet;
//import java.sql.SQLException;
//import java.util.ArrayList;
//import java.util.Properties;
//
//public class MyHandleDBNice {
//    public Connection connection;
//
//    public MyHandleDBNice() {
//        this.conn();
//    }
//
//    private void conn() {
//        try {
//            Properties properties = new Properties();
//            FileInputStream fileInputStream = new FileInputStream("src/jdbc/DruidJdbc.properties");
//            properties.load(fileInputStream);
//
//            //使用德鲁伊数据库连接池技术
//            DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
//            this.connection = dataSource.getConnection();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//    /**
//     * 查询所有数据
//     *
//     * @param sql 查询语句
//     * @return 数据集合
//     */
//    public ArrayList<Brand> findAllData(String sql) {
//        ArrayList<Brand> brands = null;
//        try {
//            PreparedStatement statement = connection.prepareStatement(sql);
//            ResultSet resultSet = statement.executeQuery();
//            brands = new ArrayList<>();
//            while (resultSet.next()) {
//                Brand brand = new Brand();
//                brand.setDEPTNO(resultSet.getInt("DEPTNO"));
//                brand.setDNAME(resultSet.getString("DNAME"));
//                brand.setLOC(resultSet.getString("LOC"));
//                brands.add(brand);
//            }
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        return brands;
//}
//
//
//    /**
//     *添加数据
////     * @param brand
//     * @return
//     * @throws SQLException
//     */
////       public int insert(Brand brand) throws SQLException {
////        String sql = "insert into dept values(?,?,?)";
////        PreparedStatement prestatement = connection.prepareStatement(sql);
////        prestatement.setInt(1, brand.getDEPTNO());
////        prestatement.setString(2, brand.getDNAME());
////        prestatement.setString(3, brand.getLOC());
////        int i = prestatement.executeUpdate();
////        return i;
////
////    }
//
//
//
//    public static void main(String[] args) throws SQLException {
//        MyHandleDBNice myHandleDBNice = new MyHandleDBNice();
//        System.out.println("myHandleDBNice.connection = " + myHandleDBNice.connection);
//        ArrayList<Brand> allData = myHandleDBNice.findAllData("select * from dept");
//        System.out.println("allData = " + allData);
//        Brand brand1 = new Brand();
//        int insert = myHandleDBNice.insert(brand1);
//        System.out.println("插入了 = " + insert+"条数据");
//    }
//
//}
